package com.simple.javatraining.testing.io;


import java.io.*;
import java.util.Calendar;

public class Logger {
    private String userName;
    private double resultOfTesting;
    private String date;

    public Logger(String userName, double resultInPercents) {
        this.userName = userName;
        this.resultOfTesting = resultInPercents;
        this.date = getCurrentDate();
    }

    public void addInfoToLog() {
        PrintWriter writer = null;
        try {
            writer = new PrintWriter(new FileWriter("log.txt", true));
        }
        catch(IOException e) {
            System.out.println("Ошибка открытия файла log.txt");
            System.exit(0);
        }
        writer.printf("%s\t\t\t%.1f%%\t\t%s\n",userName, resultOfTesting, date);
        writer.close();
    }
    private String getCurrentDate() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime().toString();
    }
}
